
#ifndef _SERVER_H_
#define _SERVER_H_

#include "dynamicarray.h"
#include "filelist.h"
#include <assert.h>
#include <pthread.h>

#define FILEDIR "./Films"

struct s_Server
{
    char* address;
    char* port;
    int socket;
    FileList filelist;
    DynamicArray clients;
    pthread_mutex_t mutex;
} typedef Server;

void server_create(Server** server, char* port);
int server_initialize(Server* server, char* port);
void server_clear(Server* server);
void server_destroy(Server** server);
int server_init(char* port, int* socket);
int server_accept(Server *server);
int server_serveClient(Server *server, int *pclient);
int * server_getClientAddress(const Server* server, int client);
int server_getClientByIndex(Server *server, int index);
void server_write(int fd, char *buffer);
void server_readline(int fd, char *buffer, int max);
int server_getFile(Server *server, int socket, char* command);
int server_freeFile(Server *server, int socket, char* command);
int server_getList(int socket, char* command);
int server_compareCommand(const char* line, const char* command);
int server_compareLine(const char* line, const char* str);

#endif /*_SERVER_H_*/
